package com.jic.market.impl.skill;

import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.market.entity.skill.SkillActivityTimeConfig;
import com.jic.market.mapper.skill.SkillActivityTimeConfigMapper;
import com.jic.market.service.skill.SkillActivityTimeConfigService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 秒杀基础信息时间间隔配置表
 *
 * @author : seven
 * @version : v1.0.0
 * @email : 774329481@qq.com
 * @since : 2020-03-12 04:47:15
 */
@Service
public class SkillActivityTimeConfigServiceImpl implements SkillActivityTimeConfigService {

    @Autowired
    private SkillActivityTimeConfigMapper skillActivityTimeConfigMapper;

    @Override
    public long insert(SkillActivityTimeConfig skillActivityTimeConfig) {
        skillActivityTimeConfig.setDeleteFlag(false);
        long flag = skillActivityTimeConfigMapper.insert(skillActivityTimeConfig);
        return flag;
    }

    @Override
    public long delete(String promotionId) {
        return skillActivityTimeConfigMapper.delete(promotionId);
    }

    @Override
    public long update(SkillActivityTimeConfig skillActivityTimeConfig) {
        return skillActivityTimeConfigMapper.update(skillActivityTimeConfig);
    }

    @Override
    public SkillActivityTimeConfig queryByPrimaryKey(Long id) {
        return skillActivityTimeConfigMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<SkillActivityTimeConfig> query(SkillActivityTimeConfig skillActivityTimeConfig) {
        return skillActivityTimeConfigMapper.query(skillActivityTimeConfig);
    }

    @Override
    public PageResult<SkillActivityTimeConfig> queryPage(SkillActivityTimeConfig skillActivityTimeConfig, Page pageQuery) {
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<SkillActivityTimeConfig> list = skillActivityTimeConfigMapper.queryPage(startIndex, pageQuery.getLimit(), skillActivityTimeConfig);
        long count = skillActivityTimeConfigMapper.queryPageCount(skillActivityTimeConfig);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }

    @Override
    public List<SkillActivityTimeConfig> queryByPromotionId(String promotionId) {
        return skillActivityTimeConfigMapper.queryByPromotionId(promotionId);
    }

    @Override
    public List<String> queryTimeIdByPromotionId(String promotionId) {
        return skillActivityTimeConfigMapper.queryTimeIdByPromotionId(promotionId);
    }

    @Override
    public long updateTimeByPromotionId(String startTimeOfDate, String endTimeOfDate,
                                        String promotionId,String timeId) {
        return skillActivityTimeConfigMapper.updateTimeByPromotionId(startTimeOfDate,
                endTimeOfDate,promotionId,timeId);
    }

    @Override
    public String queryTimeIdByPromotionIdAndDate(String promotionId, String startTimeOfDate, String endTimeIfDate) {
        return skillActivityTimeConfigMapper.queryTimeIdByPromotionIdAndDate(promotionId,
                startTimeOfDate,
                endTimeIfDate);
    }

    @Override
    public SkillActivityTimeConfig queryTimeConfigByPromotionIdAndTimeId(String promotionId, String timeId) {
        return skillActivityTimeConfigMapper.queryTimeConfigByPromotionIdAndTimeId(promotionId,timeId);
    }

    @Override
    public long deleteByPromotionIdAndTimeId(String promotionId, String timeId) {
        return skillActivityTimeConfigMapper.deleteByPromotionIdAndTimeId(promotionId,timeId);
    }

    @Override
    public int insertBatch(List<SkillActivityTimeConfig> skillActivityTimeConfigs) {
        return skillActivityTimeConfigMapper.insertBatch(skillActivityTimeConfigs);
    }
}